package com.android.takeaway.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import com.android.takeaway.R;
import com.android.takeaway.bean.Food;

/**
 * 食品详情页面
 */
public class FoodActivity extends AppCompatActivity {
    private ImageView iv_foodPic;
    private TextView tv_foodName, tv_taste, tv_saleNum, tv_price;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food);
        setTitle("");
        initView();
        initData();
    }

    private void initView() {
        iv_foodPic = findViewById(R.id.iv_foodPic);
        tv_foodName = findViewById(R.id.tv_foodName);
        tv_taste = findViewById(R.id.tv_taste);
        tv_saleNum = findViewById(R.id.tv_saleNum);
        tv_price = findViewById(R.id.tv_price);
    }

    private void initData() {
        Intent intent = getIntent();//获得数据
        Food foodBean = (Food) intent.getSerializableExtra("foodBean");
        // 获取图片的资源引用
        int resourceId = getResources().getIdentifier(foodBean.getFoodPic(), "mipmap", getPackageName());
        Glide.with(this).load(resourceId).into(iv_foodPic);
        tv_foodName.setText("名称：" + foodBean.getFoodName());
        tv_taste.setText("口味：" + foodBean.getTaste());
        tv_saleNum.setText("销量：" + foodBean.getSaleNum());
        tv_price.setText("价格：￥" + foodBean.getPrice());

    }
}